package server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Vector;

import util.Connection;

public class ServerMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Create a vector of Connections  
		
		Vector<Connection> vect= new Vector<Connection>();
		
		// TODO Next, create an instance of WatchdogThread and pass in the connections vector as 
		// the parameter
		
		WatchdogThread wdog= new WatchdogThread(vect);
		// TODO Spin up the WatchdogThread
		
		Thread wdThread = new Thread(wdog);
		wdThread.start();
		
		// TODO Accept incoming connections,
		//create Connection object and add it to connections vector
		// inside synchronized block.  
			ServerSocket ss = null;
			try {
				ss = new ServerSocket(25012);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		while(true){
			Socket clientSocket = null;
			try {
				clientSocket = ss.accept();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println("new connection happened to port " + clientSocket.getPort());
			Connection conn=new Connection(clientSocket,"",-1);
			synchronized(vect) {
				vect.add(conn);
			}
		
		}//end while loop
		
	}// end main

}//end class
